package com.wft.面试题;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class 复制文件并改名 {
    public static void main(String[] args) {
        File file = new File("D:\\git\\design-pattern\\src\\main\\java\\com\\wft\\singleton");
        copyFiles("D:\\git\\design-pattern\\src\\main\\java\\com\\wft\\singleton\\", "D:\\git\\design-pattern\\src\\main\\java\\com\\wft\\singleton2");

    }

    public static void copyFiles(String sourceDir, String destDir) {
        File source = new File(sourceDir);
        List<File> fileList = Arrays.stream(source.listFiles((dir, fileName) -> fileName.endsWith(".java"))).collect(Collectors.toList());
        Arrays.stream(source.listFiles((dir, fileName) -> fileName.endsWith(".java")))
                .forEach(file -> {
                    try {
                        Files.copy(file.toPath(), new File(destDir + File.separator + file.getName().replace(".java", ".class")).toPath());
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                });
    }
}
